package com.gxa.jd.controller;

import com.gxa.jd.pojo.Order;
import com.gxa.jd.service.OrderService;
import com.gxa.entity.PageResult;
import com.gxa.entity.Result;
import com.gxa.jd.vo.OrderVo;
import com.gxa.jd.vo.OrderVoo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/order")
@Api(description = "酒店订单的接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/findAll")
    @ApiOperation(value = "根据用户id查询所有订单信息",notes = "根据用户id查询所有订单信息")
    public List<OrderVoo> findAll(Long id) {
        return orderService.findAll(id);
    }

    @GetMapping("/findAllState")
    @ApiOperation(value = "根据用户id和订单状态查询所有订单信息",notes = "根据用户id和订单状态查询所有订单信息")
    public List<OrderVoo> findAllByState(Long id, Integer state) {
        return orderService.findAllByState(id,state);
    }

    @GetMapping("/findPage")
    @ApiOperation(value = "分页查询",notes = "分页查询")
    public PageResult<Order> findPage(int page, int size) {
        return orderService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Order> findList(@RequestBody Map<String, Object> searchMap) {
        return orderService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Order> findPage(@RequestBody Map<String, Object> searchMap, int page, int size) {
        return orderService.findPage(searchMap, page, size);
    }

    @GetMapping("/findById")
    @ApiOperation(value = "根据订单号查询订单信息",notes = "根据订单号查询订单信息")
    public OrderVo findByOrderNum(String orderNum) {
        return orderService.findByOrderNum(orderNum);
    }


    @PostMapping("/add")
    @ApiOperation(value = "添加订单信息",notes = "添加订单信息")
    public Result add(@RequestBody Order order) {
        orderService.add(order);
        return new Result();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改订单信息",notes = "修改订单信息")
    public Result update(@RequestBody Order order) {
        orderService.update(order);
        return new Result();
    }

    @GetMapping("/delete")
    @ApiOperation(value = "删除订单信息",notes = "删除订单信息")
    public Result delete(String orderNum) {
        orderService.delete(orderNum);
        return new Result();
    }

}
